package nbcp.myoql.code.generator.db.sql


import nbcp.myoql.code.generator.db.mysql.model.TableColumnMetaData
import nbcp.myoql.code.generator.db.mysql.model.TableIndexMetaData
import nbcp.myoql.code.generator.db.mysql.model.TableMetaData
import nbcp.myoql.db.db
import nbcp.myoql.db.enums.SqlDatabaseEnum
import nbcp.myoql.db.sql.enums.DbType

interface ISqlMetadata {
    fun getDbType(dataType: String): DbType

    companion object {
        @JvmStatic
        val instance: ISqlMetadata
            get() {
                var dbType = db.sql.getCurrentScopeSqlDatabaseEnum()
                if (dbType == SqlDatabaseEnum.MY_SQL || dbType == SqlDatabaseEnum.MARIA_DB) {
                    return MysqlImpl()
                }

                if (dbType == SqlDatabaseEnum.POSTGRESQL) {
                    return PostgreImpl()
                }

                throw RuntimeException("未实现的数据库解析类型: ${dbType}");
            }
    }

    fun getTables(): List<TableMetaData>
    fun getColumns(): List<TableColumnMetaData>
    fun getIndexes(): List<TableIndexMetaData>
}